package com.hr.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * 用户表(Users)表实体类
 *
 * @author makejava
 * @since 2022-04-13 09:00:44
 */
@SuppressWarnings("serial")
@TableName("users")
public class Users implements UserDetails {
    //主键，自动增长列
    @TableId(type= IdType.AUTO,value = "u_id")
    private Integer uid;
    //用户名
    @TableField("u_name")
    private String uname;
    //真实姓名
    @TableField("u_true_name")
    private String utrueName;
    //密码(注：是密文）
    @TableField("u_password")
    private String upassword;
    //用户身份（关联角色表）
    @TableField("r_id")
    private Integer rid;
    //保证mybatisPlus 能给正常使用  exist=false
    @TableField(exist=false)
    private Role role;

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    //用户角色/权限 列表
    @TableField(exist = false)
    private List<GrantedAuthority> authorities;

    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    public String getUname() {
        return uname;
    }

    public void setUname(String uname) {
        this.uname = uname;
    }

    public String getUtrueName() {
        return utrueName;
    }

    public void setUtrueName(String utrueName) {
        this.utrueName = utrueName;
    }

    public String getUpassword() {
        return upassword;
    }

    public void setUpassword(String upassword) {
        this.upassword = upassword;
    }

    public Integer getRid() {
        return rid;
    }

    public void setRid(Integer rid) {
        this.rid = rid;
    }

    @Override
    public String toString() {
        return "Users{" +
                "uid=" + uid +
                ", uname='" + uname + '\'' +
                ", utrueName='" + utrueName + '\'' +
                ", upassword='" + upassword + '\'' +
                ", rid=" + rid +
                ", role=" + role +
                ", authorities=" + authorities +
                '}';
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }
    public void setAuthorities(List<GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    @Override
    public String getPassword() {
        return upassword;
    }

    @Override
    public String getUsername() {
        return uname;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}

